package cn.micai.base.string;

/**
 * 描述：How to convert Char Array to String in java
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/11 15:31
 */
public class CharArrToStringMain {

    public static void main(String [] args) {

        char [] charArr = {'J', 'a', 'v', 'a', '2', 'b', 'l', 'o', 'g'};

        // Using String`s constructor
        System.out.println("--------------------");
        System.out.println("Using String's contructor");
        System.out.println("--------------------");
        String str = new String(charArr);
        System.out.println(str);
        System.out.println();

        // Using String`s valueOf method
        System.out.println("--------------------");
        System.out.println("Using String's valueOf");
        System.out.println("--------------------");
        String strV = String.valueOf(charArr);
        System.out.println(strV);
        System.out.println();

        // Using iterating char Array
        System.out.println("--------------------");
        System.out.println("Using iterating char Array");
        System.out.println("--------------------");
        String strT = "";
        for (int i=0; i<charArr.length; i++) {
            strT += charArr[i];
        }
        System.out.println(strT);

    }
}
